# -*- coding: UTF-8 -*-
# server_assets
# @File : CharacterZhanYi.py
# @Date : 2023-08-30
# @Author  : wuzhouhai
# @Desc:
import KBEngine
from KBEDebug import *
import time
import ConstantDefine
import s_guaqiaInfo
import s_partyInfo
import s_monster
from common import randomObject
from objects.Monster import Monster
from module.battleSide import BattleSide
from module.fight import Fight

TEAM_FIGHT_RECOVERY_INTERVAL = 1800


class CharacterZhanYi:
    """角色的战役信息
    """

    def __init__(self):
        """初始化爬塔信息
        """
        self.record = {}  # 角色战役记录
        self._initSyncFinghtInfo = True
        self._FightResult = None
        self._autoFightInfo = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 'notJob': 0}
        self._teamFightData = {}
        self._teamFightMaxTimes = 0  # 组队战次数上限
        self._teamFightRecoveryTime = 0  # 组队战恢复次数开始时间
        self._teamFightTimes = 0  # 组队战次数
        self._teamResetTimes = 0  # 重置组队战次数
        self._teamResetFreeTimes = 0  # 重置组队战免费次数
        self._teamFightMember = []  # 组队战可选队员
        self._checkKickOutCounts = 0  # 检测频繁战斗次数
        # 世界BOSS相关
        self._worldBossCheerCanUseTime = 0
        self._worldBossCheer = 0  # 世界BOSS鼓舞层数
        self._worldBossRevive = 0  # 世界BOSS复活次数

    def zhanyiInitTimes(self):
        """初始化战役次数"""
        self._teamFightMaxTimes = self.getSystemTotalTimes(ConstantDefine.TEAM_FIGHT_MAX)  # 组队战次数上限
        self._worldBossCheerCanUseTime = self.getSystemTotalTimes(ConstantDefine.WORLDBOSS_CHEER)

    def zhanyiInit(self):
        """战役初始化操作"""
        self.checkStartTeamFightRecovery()
        self.checkTeamFightRecoveryTime()

    def resetTeamFightData(self):
        """重置组队战"""
        del self._teamFightData.FightDatas[:]
        # for teamFightGuanQia in dbZhanyi.ALL_TEAMFIGHT.values():
        #     teamFight = self._teamFightData.FightDatas.add()
        #     teamFight.TeamFightGuanQia = teamFightGuanQia['id']
        #     teamFight.TeamFightTimes = 0

    def getTeamFightDatas(self):
        """获取组队战信息"""
        return self._teamFightData.FightDatas

    def initTeamFightDataFromDB(self, data):
        """从数据库初始化组队战信息"""
        # if not data:
        #     return
        # else:
        #     try:
        #         self._teamFightData.ParseFromString(base64Operate.DataDecode(data, 'role_teamFight'))
        #     except Exception as e:
        #         self._teamFightData = guaji_pb2.StructTeamFightData()  # 组队战信息
        pass

    def getTeamFightDataToByte(self):
        """序列化组队战"""
        return base64Operate.DataEncode(self._teamFightData.SerializePartialToString())

    def addTeamFightTimesByGuanQia(self, guanQia, teamFightGuanQiaInfo):
        """增加组队战关卡战斗次数"""
        if not teamFightGuanQiaInfo['fightMaxTimes']:
            return
        for teamFight in self._teamFightData.FightDatas:
            if teamFight.TeamFightGuanQia == guanQia:
                teamFight.TeamFightTimes += 1
                return
        teamFight = self._teamFightData.FightDatas.add()
        teamFight.TeamFightGuanQia = guanQia
        teamFight.TeamFightTimes = 1

    def checkTeamFightGuanQiaTimes(self, guanQia, teamFightGuanQiaInfo):
        """检测组队战关卡次数"""
        if not teamFightGuanQiaInfo['fightMaxTimes']:
            return True
        for teamFight in self._teamFightData.FightDatas:
            if teamFight.TeamFightGuanQia == guanQia and teamFight.TeamFightTimes >= teamFightGuanQiaInfo[
                'fightMaxTimes']:
                return False

        return True

    def setTeamRecoveryTime(self, recoveryTime):
        """设置组队战恢复开始时间"""
        self._teamFightRecoveryTime = recoveryTime

    def getTeamRecoveryTime(self):
        """获取组队战恢复开始时间"""
        return self._teamFightRecoveryTime

    def checkStartTeamFightRecovery(self):
        """检查是否开始组队战次数恢复"""
        # print u'组队战次数:%d,组队战最大次数:%d,账号名:%s'%(self._teamFightTimes,self._teamFightMaxTimes,self._owner.baseInfo.getNickName())
        if self._teamFightRecoveryTime > 0 or self._teamFightTimes >= self._teamFightMaxTimes:
            return

        self._teamFightRecoveryTime = int(time.time())

    def checkTeamFightRecoveryTime(self):
        """检测组队战恢复时间"""
        if not self._teamFightRecoveryTime:
            return
        intervalTime = int(time.time()) - self._teamFightRecoveryTime
        if intervalTime < TEAM_FIGHT_RECOVERY_INTERVAL:
            return
        canIntertvalTimes = self._teamFightMaxTimes - self._teamFightTimes  # 可以恢复的次数
        intertvalTimes = int(intervalTime / TEAM_FIGHT_RECOVERY_INTERVAL)  # 恢复次数
        if canIntertvalTimes < intertvalTimes:
            intertvalTimes = canIntertvalTimes
            self._teamFightRecoveryTime = 0
        else:
            self._teamFightRecoveryTime += intertvalTimes * TEAM_FIGHT_RECOVERY_INTERVAL

        self.addTeamFightTimes(intertvalTimes)
        # print u'恢复组队战次数:%d,当前组队战次数:%d,组队战最大次数:%d'%(intertvalTimes,self._teamFightTimes,self._teamFightMaxTimes)

    def setTeamFightMaxTimes(self, maxTimes):
        """设置组队战次数上限"""
        self._teamFightMaxTimes = maxTimes
        self.checkStartTeamFightRecovery()

    def getTeamFightMaxTimes(self):
        """获取组队战次数上限"""
        return self._teamFightMaxTimes

    def addTeamFightTimes(self, addTimes=1):
        """增加组队战次数"""
        self._teamFightTimes += addTimes
        if self._teamFightMaxTimes < self._teamFightTimes:
            self._teamFightTimes = self._teamFightMaxTimes
        if self._teamFightMaxTimes == self._teamFightTimes:
            self._teamFightRecoveryTime = 0

    def setTeamFightTimes(self, fightTimes):
        """设置组队战剩余次数"""
        self._teamFightTimes = fightTimes
        if self._teamFightMaxTimes < self._teamFightTimes:
            self._teamFightTimes = self._teamFightMaxTimes
        self.checkStartTeamFightRecovery()

    def getTeamFightTimes(self):
        """获取组队战剩余次数"""
        return self._teamFightTimes

    def delTeamFightTimes(self):
        """扣除组队战次数"""
        self._teamFightTimes -= 1
        if self._teamFightTimes < 0:
            self._teamFightTimes = 0
        self.checkStartTeamFightRecovery()

    def setTeamResetTimes(self, resetTimes):
        """设置重置组队战次数"""
        self._teamResetTimes = resetTimes

    def getTeamResetTimes(self):
        """获取重置组队战次数"""
        return self._teamResetTimes

    def delResetTeamFightTimes(self):
        """扣除重置组队战次数"""
        self._teamResetTimes -= 1
        if self._teamResetTimes < 0:
            self._teamResetTimes = 0

    def setTeamResetFreeTimes(self, resetTimes):
        """设置免费重置次数"""
        self._teamResetFreeTimes = resetTimes

    def getTeamResetFreeTimes(self):
        """获取重置组队战免费次数"""
        return self._teamResetFreeTimes

    def delResetTeamFightFreeTimes(self):
        """扣除重置组队战次数"""
        self._teamResetFreeTimes -= 1
        if self._teamResetFreeTimes < 0:
            self._teamResetFreeTimes = 0

    def initAutoFightInfo(self, data):
        """初始化挂机信息"""
        if not data:
            return

        # autoFightInfo = guajidata_pb2.StructAutoFightInfo()
        # try:
        #     autoFightInfo.ParseFromString(base64Operate.DataDecode(data, 'role_AutoFight'))
        # except Exception as e:
        #     autoFightInfo = guajidata_pb2.StructAutoFightInfo()
        # autoFightKeys = [1, 2, 3, 4, 5, 6, 'notJob']
        # index = 0
        # for mark in autoFightInfo.EquipSell:
        #     if index > len(autoFightKeys) - 1:
        #         break
        #     self._autoFightInfo[autoFightKeys[index]] = mark
        #     index += 1
        pass

    def getAutoFightInfoToBytes(self):
        """获取挂机信息序列化数据"""
        autoFightInfo = guajidata_pb2.StructAutoFightInfo()
        for make in self._autoFightInfo.values():
            autoFightInfo.EquipSell.append(make)
        return base64Operate.DataEncode(autoFightInfo.SerializePartialToString())

    def setAutoFightInfo(self, fightDict):
        """设置挂机信息"""
        for key, make in fightDict.items():
            if make == 0:
                self._autoFightInfo[key] = make
            else:
                self._autoFightInfo[key] = 1

    #         print  'self._autoFightInfo:%s'%self._autoFightInfo
    def getAutoFightInfo(self):
        """获取挂机信息"""
        return self._autoFightInfo

    def setOffLineTime(self, value):
        """设置离线时间"""
        self._offLineTime = value

    def getOffLineTime(self):
        """获取离线时间"""
        return self._offLineTime

    def setFightWinOdds(self, value):
        """设置关卡胜率"""
        if value > 100:
            value = 100
        elif value < 60:
            value = 60

        self._fightWinOdds = value

    def getFightWinOdds(self):
        """获取关卡胜率"""
        return self._fightWinOdds

    def setFightWinCounts(self, value):
        """设置关卡胜利次数"""
        self._fightWinCounts = value

    def getFightWinCounts(self):
        """获取关卡胜利次数"""
        return self._fightWinCounts

    def setGuanQiaOdds(self, value):
        """设置关卡掉率"""
        self._guanQiaOdds = value

    def getGuanQiaOdds(self):
        """获取关卡掉率"""
        return self._guanQiaOdds

    def setFightReTime(self, value):
        """设置战斗请求时间"""
        self._fightRequestTime = value

    def getFightReTime(self):
        """获取战斗请求时间"""
        return self._fightRequestTime

    def setFightTime(self, value, sync=False):
        """设置每场战斗时间"""
        if value > 0:
            self._fightTime = value

        if sync:
            self.syncFightInfo()

    def getFightTime(self):
        """获取每场战斗时间"""
        return self._fightTime

    def setTotalFightCounts(self, value):
        """设置战斗总次数"""
        self._totlaFightCounts = value

    def getTotalFightCounts(self):
        """获取战斗总次数"""
        return self._totlaFightCounts

    def setTown(self, town):
        """设置场景ID"""
        self._town = town

    def getTown(self):
        """获取场景ID"""
        return self._town

    def setGuanQia(self, guanqia, clearFightInfo=False):
        """设置关卡ID"""
        oldGuanQia = self._guanqia
        self._guanqia = guanqia

        if clearFightInfo and oldGuanQia != self._guanqia:
            guanQiaInfo = self._getZhanYiInfo()
            self._fightTime = guanQiaInfo['fightTime']
            self._guanQiaOdds = guanQiaInfo['dropOdds']
            self._fightWinOdds = 80
            self._totlaFightTime = guanQiaInfo['fightTime']
            self.setTotalFightCounts(0)
            self.setFightWinCounts(0)
            self.setFightReTime(0)

    def getGuanQia(self):
        """获取关卡ID"""
        return self._guanqia

    def setMaxGuanQia(self, maxGuanQia, refreshTime=False):
        """设置当前最大关卡ID"""
        self._maxGuanQia = maxGuanQia

    def getMaxGuanQia(self):
        """获取当前最大关卡ID"""
        return self._maxGuanQia

    def setMaxJYGuanQia(self, maxGuanQia):
        """设置当前最大关卡ID"""
        self._maxJYGuanQia = maxGuanQia

    def getMaxJYGuanQia(self):
        """获取当前最大关卡ID"""
        return self._maxJYGuanQia

    def setFastFightTimes(self, fightTimes):
        """设置快速战斗次数"""
        self._fastFightTimes = fightTimes

    def getFastFightTimes(self):
        """获取快速战斗次数"""
        return self._fastFightTimes

    def addFastFightTimes(self, addTimes=1):
        """增加快速战斗次数"""
        self.setFastFightTimes(self.getFastFightTimes() + addTimes)

    def delFastFightTimes(self, addTimes=1):
        """减少快速战斗次数"""
        if self.getFastFightTimes() < addTimes:
            self.setFastFightTimes(0)
            return

        self.setFastFightTimes(self.getFastFightTimes() - addTimes)

    def setFightBossTimes(self, fightTimes):
        """设置挑战BOSS剩余次数"""
        self._fightBossTimes = fightTimes

    def getFightBossTimes(self):
        """获取挑战BOSS剩余次数"""
        return self._fightBossTimes

    def addFightBossTimes(self, addTimes=1):
        """增加挑战BOSS次数"""
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_BOSSTIMES)
        self.setFightBossTimes(self.getFightBossTimes() + addTimes)

    def delFightBossTimes(self, addTimes=1):
        """减少挑战BOSS次数"""
        if self.getFightBossTimes() < addTimes:
            self.setFightBossTimes(0)
            return

        self.setFightBossTimes(self.getFightBossTimes() - addTimes)

    def getWorldBossCheerCanUse(self):
        """获取世界BOSS可使用总次数"""
        return self._worldBossCheerCanUseTime

    def setWorldBossCheer(self, setValue=0):
        """设置世界BOSS鼓舞层数"""
        self._worldBossCheer = setValue

    def getWorldBossCheer(self):
        """获取世界BOSS鼓舞层数"""
        return self._worldBossCheer

    def getWorldBossRevive(self):
        """获取世界BOSS复活次数"""
        return self._worldBossRevive

    def addWorldBossCheer(self):
        """增加鼓舞层数"""
        # if not vipManager.CheckCanUseWorldBossWish(self.getVipLevel()):
        #     return False, u'vip等级不足'
        # if not self._owner.checkSystemTimes(dbGameConfig.WORLDBOSS_CHEER):
        #     return False, u'次数已经用完'
        #
        # if not self._owner.checkSystemExpend(dbGameConfig.WORLDBOSS_CHEER, dbGameLog.SYSTEM_ID_CHEER):
        #     return False, u'货币不足'
        #
        # if self.getWorldBossCheer() >= 10:
        #     return False, u'已达最大层数'
        #
        # self.setWorldBossCheer(self.getWorldBossCheer() + 1)
        # WorldManager().addWorldBossCheerTimes(self._owner.getBaseID())
        #
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_CHEER)

        return True, u'成功'

    def worldBossRevive(self):
        """BOSS战复活"""
        # if not vipManager.CheckCanUseWorldBossRevive(self._owner.level.getVipLevel()):
        #     return False, u'vip等级不足'
        #
        # # if not self._owner.checkSystemTimes(dbGameConfig.WORLDBOSS_REVIVE):
        # #     return False, u'次数已经用完'
        #
        # if not self._owner.checkSystemExpend(dbGameConfig.WORLDBOSS_REVIVE, dbGameLog.SYSTEM_ID_BOSSREVIVE):
        #     return False, u'货币不足'
        #
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_BOSSREVIVE)
        # self._worldBossRevive += 1
        return True, u'成功'

    def syncFightInfo(self):
        """同步挂机战斗信息到前端"""
        # guankaInfo = self._getZhanYiInfo()
        # if not guankaInfo:
        #     #             print 'no guanka info !!!!!!'
        #     return
        # partys = [guankaInfo['monsterParty1'], guankaInfo['monsterParty2'], guankaInfo['monsterParty3'],
        #           guankaInfo['monsterParty4']]
        # partysProbs = [guankaInfo['monsterParty1Prob'], guankaInfo['monsterParty2Prob'],
        #                guankaInfo['monsterParty3Prob'], guankaInfo['monsterParty4Prob']]
        # msgSyncFightInfo = guaji_pb2.MsgSyncFightInfoResult()
        # msgSyncFightInfo.Result = 'TRUE'
        # msgSyncFightInfo.FightAverage = self.getFightTime()
        # msgSyncFightInfo.FightCounts = int(3600 / self.getFightTime())
        # msgSyncFightInfo.FightWinOdds = self.getFightWinOdds()
        # if self._guanQiaOdds == 0:
        #     self.setGuanQiaOdds(guankaInfo['dropOdds'])
        # msgSyncFightInfo.FightDropOdds = int((self._guanQiaOdds / float(10000)) * 100)
        # #         print u'装备掉率:%d'%msgSyncFightInfo.FightDropOdds
        # oddsTotla = 0
        # for odds in partysProbs:
        #     oddsTotla += odds
        #
        # for index, partyId in enumerate(partys):
        #     partyInfo = dbMonster.ALL_MONSTER_PARTY_INFO.get(partyId)
        #     if not partyInfo:
        #         continue
        #     fightPartyCounts = int(msgSyncFightInfo.FightCounts * (partysProbs[index] / float(oddsTotla)) * (
        #                 msgSyncFightInfo.FightWinOdds / float(100)))
        #
        #     msgSyncFightInfo.FightDropExp += fightPartyCounts * partyInfo['exp']
        #     msgSyncFightInfo.FightDropCoin += fightPartyCounts * partyInfo['money']
        #
        # data = msgSyncFightInfo.SerializePartialToString()
        # pushObject(4504, data, [self._owner.dynamicId])  # 主动推送消息
        pass

    def fillZhanYiInfoById(self, guanqia):
        """根据关卡ID来填写关卡信息"""
        guankaInfo = s_guaqiaInfo.datas.get(guanqia)
        #         print 'zhanyiinfo:%s'%dbZhanyi.ALL_ZHANYI_INFO
        #         print 'guanqia : %d'%guanqia
        if not guankaInfo:
            #             print 'ChooseGuankaInfoError!'
            return {}

        info = {'name': guankaInfo['name'], 'chapterId': guankaInfo['chapterId'], 'needLevel': guankaInfo['needLevel'],
                'fightTime': guankaInfo['fightTime'], 'dropOdds': guankaInfo['dropOdds'],
                'needCurrencyType': guankaInfo['needCurrencyType'], 'needCurrencyNum': guankaInfo['needCurrencyNum'],
                'needItemType': guankaInfo['needItemType'], 'needItemNum': guankaInfo['needItemNum'],
                'monsterParty1': guankaInfo['monsterParty1'], 'monsterParty1Prob': guankaInfo['monsterParty1Prob'],
                'monsterParty2': guankaInfo['monsterParty2'], 'monsterParty2Prob': guankaInfo['monsterParty2Prob'],
                'monsterParty3': guankaInfo['monsterParty3'], 'monsterParty3Prob': guankaInfo['monsterParty3Prob'],
                'monsterParty4': guankaInfo['monsterParty4'], 'monsterParty4Prob': guankaInfo['monsterParty4Prob'],
                'monsterBossPaety': guankaInfo['monsterBossPaety']}
        return info

    def _getZhanYiInfo(self):
        """获取角色的当前战役信息
        """
        return self.fillZhanYiInfoById(self._guanqia)

    def monsterTempletFactory(self, partyId):
        monsterTempletGroup = []
        # monsterGroup = []
        partyInfo = s_partyInfo.datas.get(partyId)
        if not partyInfo:
            #             print 'ChooseMonsterError!'
            return {}

        # monsterCount = partyInfo['fightNum']
        if partyInfo['monsterId1'] != 0:
            monsterTempletGroup.append({'monsterTId': partyInfo['monsterId1'], 'monsterPosition': 1})
        if partyInfo['monsterId2'] != 0:
            monsterTempletGroup.append({'monsterTId': partyInfo['monsterId2'], 'monsterPosition': 2})
        if partyInfo['monsterId3'] != 0:
            monsterTempletGroup.append({'monsterTId': partyInfo['monsterId3'], 'monsterPosition': 3})
        if partyInfo['monsterId4'] != 0:
            monsterTempletGroup.append({'monsterTId': partyInfo['monsterId4'], 'monsterPosition': 4})
        if partyInfo['monsterId5'] != 0:
            monsterTempletGroup.append({'monsterTId': partyInfo['monsterId5'], 'monsterPosition': 5})
        if partyInfo['monsterId6'] != 0:
            monsterTempletGroup.append({'monsterTId': partyInfo['monsterId6'], 'monsterPosition': 6})

        # for _ in range(monsterCount):
        #     index = random.randrange(0,len(monsterTempletGroup))
        #     monsterGroup.append(monsterTempletGroup[index])

        return monsterTempletGroup

    def formatErrorFightData(self, errString=''):
        msgFightResult = MsgFightResult()  # 战斗结果对象
        msgFightResult.Result = 0
        msgFightResult.ResultInfo = errString
        return msgFightResult.SerializePartialToString()

    def doWorldBoss(self, fightType):
        """世界BOSS战斗"""
        # if WorldManager().checkIsFightWorldBoss(self._owner.baseInfo.getId()):
        #     self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_WORLDBOSSTIMES, 1, changeKey=0, isAdd=True)
        #     self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_WORLDBOSSID, 1,
        #                                               changeKey=WorldManager().getWorldBossId(), isAdd=True)
        #     self._owner.guild.updateGuildTask(dbTask.TASK_CONDITION_WORLDBOSSTIMES, 1, changeKey=0, isAdd=True)
        #     self._owner.guild.updateGuildTask(dbTask.TASK_CONDITION_WORLDBOSSID, 1,
        #                                       changeKey=WorldManager().getWorldBossId(), isAdd=True)
        #
        # defHordeGroup = [WorldManager().getWorldBoss()]  # 防守方对象
        # attackBattleSide = self._owner.matrix.getFightMatrix()  # 进攻方阵
        # defBattleSide = BattleSide(defHordeGroup, 2, 4)  # 防守方阵
        # data = Fight(attackBattleSide, defBattleSide, 0, self._guanqia, isWorldBoss=True)
        # data.DoFight()
        # if data.battleResult == 1:  # 世界BOSS最后一击
        #     WorldManager().setWorldBossHp(0)
        #     self.syncWorldBossStatus()
        #     WorldManager().updatePlayerAtkBossInfo(self._owner, data.worldBossHp)
        #     data.partyMoney = data.worldBossHp
        #     self._owner.finance.addCoin(data.partyMoney)
        #     WorldManager().closeWorldBossEvent(self._owner.getBaseID(), self._owner.baseInfo.getNickName())
        # else:
        #     WorldManager().setWorldBossHp(data.worldBossReMindHp)
        #     WorldManager().updatePlayerAtkBossInfo(self._owner, data.worldBossHp - data.worldBossReMindHp)
        #     bossMaxHp = WorldManager().getWorldBossMaxHp()
        #     if bossMaxHp > 0:
        #         data.partyMoney = int(5000 * (data.worldBossHp - data.worldBossReMindHp) / float(bossMaxHp))
        #     self._owner.finance.addCoin(data.partyMoney)
        #     self.syncWorldBossStatus()
        #
        # result = data.formatFightData(fightType, fightBossTimes=self.getFightBossTimes())
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_WORLDBOSS)
        # self._owner.pack.SyncPackChange()
        # return result
        pass

    def syncWorldBossStatus(self):
        """同步BOSS状态"""
        # msg = guaji_pb2.MsgSyncWorldBossStatusResult()
        # msg.Result = 'TRUE'
        # msg.BossHp = WorldManager().getWorldBossHp()
        # msg.BossMaxHp = WorldManager().getWorldBossMaxHp()
        # msg.IsAlive = {False: 0, True: 1}.get(msg.BossHp > 0)
        # data = msg.SerializePartialToString()
        # gateWorldBossBroadcast(605, data)
        pass

    def getWorldBossStatusToRole(self):
        """推送世界BOSS状态给自己"""
        # msg = guaji_pb2.MsgGetWorldBossInfoResult()
        # msg.Result = 'TRUE'
        # msg.BossHp = WorldManager().getWorldBossHp()
        # msg.BossMaxHp = WorldManager().getWorldBossMaxHp()
        # msg.IsAlive = {False: 0, True: 1}.get(msg.BossHp > 0)
        # msg.CheerCounts = self.getWorldBossCheer()
        # data = msg.SerializePartialToString()
        # return data
        pass

    def doBeastFamBossFight(self, fightType):
        """秘境BOSS战斗"""
        # if not self._owner.beastFam.checkFightStats():
        #     return self.formatErrorFightData(u'没有召唤BOSS')
        # beastFamBossParty, bossId = self._owner.beastFam.getBeastFamBoss()
        # monsterGroup = self.monsterTempletFactory(beastFamBossParty)
        # if not monsterGroup:
        #     return self.formatErrorFightData(u'BOSS数据错误')
        # defHordeGroup = []  # 防守方对象
        # monsterid = dbMonster.MONSTER_DYNAMIC_START
        # beastFamBossId = 0
        # for monsterF in monsterGroup:
        #     monsterTempletId = monsterF['monsterTId']
        #     if monsterTempletId not in dbMonster.ALL_MONSTER_INFO.keys():
        #         return self.formatErrorFightData(u'怪物错误')
        #     monster = Monster(id=monsterid, templateId=monsterTempletId, matrixId=monsterF['monsterPosition'])
        #     if monster.templateId == bossId:
        #         monster.setMonsterHp(self._owner.beastFam.getBeastBossRemindHp())
        #         beastFamBossId = monsterid
        #     defHordeGroup.append(monster)
        #     monsterid += 1
        # if not self._owner.beastFam.checkFightBossTime():
        #     return self.formatErrorFightData(u'战斗冷却中')
        #
        # attackBattleSide = self._owner.matrix.getFightMatrix()  # 进攻方阵
        # defBattleSide = BattleSide(defHordeGroup, 2, 1)  # 防守方阵
        # data = Fight(attackBattleSide, defBattleSide, 0, self._guanqia)
        # data.DoFight()
        # if data.battleResult == 1:  # 最后一击
        #     self._owner.beastFam.setBeastBossRemindHp(0)
        #     self._owner.beastFam.setBeastFamStats(3)
        # else:
        #     self._owner.beastFam.setBeastBossRemindHp(data.fighters[beastFamBossId]['chaCurrentHp'])
        #
        # result = data.formatFightData(fightType, fightBossTimes=self.getFightBossTimes())
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_BEASTFAMFIGHT)
        # self._owner.pack.SyncPackChange()
        # return result
        pass

    def getTeamFightParty(self, teamFightGuanQiaInfo):
        """获取组队战Party"""
        # partyLevel = self._owner.level.getLevel() / 5 * 5
        # if partyLevel == 0:
        #     partyLevel = 5
        # # print 'party level %d,partyGroup %d,partyLevelInfo：%s'%(partyLevel,teamFightGuanQiaInfo['partyGroup'],dbZhanyi.ALL_LEVEL_PARTY)
        # return dbZhanyi.ALL_LEVEL_PARTY.get(teamFightGuanQiaInfo['partyGroup'], {}).get(partyLevel, -1)
        pass

    def doTeamFight(self, fightType, teamMemberList, teamFightGuanQia, teamFightDifficulty):
        """组队战"""
        # teamFightGuanQiaInfo = dbZhanyi.ALL_TEAMFIGHT.get(teamFightGuanQia, {})
        # if not teamFightGuanQiaInfo:
        #     return self.formatErrorFightData(u'组队战关卡错误')
        # if not self.checkTeamFightGuanQiaTimes(teamFightGuanQia, teamFightGuanQiaInfo):
        #     return self.formatErrorFightData(u'关卡次数已用光')
        # if self._owner.level.getLevel() < teamFightGuanQiaInfo.get('fightLevel', 0):
        #     return self.formatErrorFightData(u'等级不足')
        # teamFightMonsterParty = self.getTeamFightParty(teamFightGuanQiaInfo)
        # if teamFightMonsterParty == -1:
        #     return self.formatErrorFightData(u'组队战怪物组配置错误')
        # defHordeGroup = []  # 防守方对象
        # monsterGroup = self.monsterTempletFactory(teamFightMonsterParty)
        # if not monsterGroup:
        #     return self.formatErrorFightData(u'组队战怪物组错误')
        # monsterid = dbMonster.MONSTER_DYNAMIC_START
        # for monsterF in monsterGroup:
        #     monsterTempletId = monsterF['monsterTId']
        #     if not dbMonster.ALL_MONSTER_INFO.has_key(monsterTempletId):
        #         return self.formatErrorFightData(u'组队战怪物错误')
        #     monster = Monster(id=monsterid, templateId=monsterTempletId, matrixId=monsterF['monsterPosition'])
        #     defHordeGroup.append(monster)
        #     monsterid += 1
        # atkHordeGroup = [self._owner]  # 进攻方对象
        # from app.game.core.character.PlayerCharacter import PlayerCharacter
        # from app.game.core.PlayersManager import PlayersManager
        # for teamMemberId in teamMemberList:
        #     athleticsPlayer = PlayersManager().getPlayerByID(teamMemberId)
        #     if not athleticsPlayer:
        #         athleticsPlayer = PlayerCharacter(teamMemberId, calculateOffLine=False)
        #     else:
        #         athleticsPlayer = copy.deepcopy(athleticsPlayer)
        #     atkHordeGroup.append(athleticsPlayer)
        # attackBattleSide = BattleSide(atkHordeGroup, 1, 3)  # 进攻方阵
        # defBattleSide = BattleSide(defHordeGroup, 2, 1)  # 防守方阵
        # data = Fight(attackBattleSide, defBattleSide, teamFightMonsterParty, teamFightGuanQia)
        # data.DoFight()
        # if data.battleResult == 1:
        #     data.DoRewordLoot()
        #     data.partyExp, data.partyMoney = self._owner.events.calculateEarningsBuff(data.partyExp, data.partyMoney)
        #     self._owner.level.addExp(data.partyExp)
        #     self._owner.finance.addCoin(data.partyMoney)
        #     self._owner.pet.updatePetSoul(data.partySkillPoints)  # 增加魂玉
        #     self.addTeamFightTimesByGuanQia(teamFightGuanQia, teamFightGuanQiaInfo)
        # sellCoin = 0
        # for index, item in enumerate(data.lootList):
        #     itemTempletInfo = dbItems.all_ItemTemplate.get(item['itemId'], None)
        #     if not itemTempletInfo:
        #         continue
        #     if itemTempletInfo['itemPage'] == 1:  # 装备
        #         for _ in range(item['itemNum']):
        #             if itemTempletInfo['qualityId'] != 0 and itemTempletInfo['attributeGroupId'] != 0:
        #                 quality = ItemAttributeComponent.createItemQuality(itemTempletInfo['qualityId'])
        #             else:
        #                 quality = itemTempletInfo['baseQuality']
        #
        #             # 检测挂机设置自动售卖机制
        #             if self._autoFightInfo[quality] == 1:  # 品质
        #                 sellCoin += itemTempletInfo['buyingRateCoin']
        #                 data.addSellItem(
        #                     {'itemId': item['itemId'], 'itemNum': 1, 'Coin': 1 * itemTempletInfo['buyingRateCoin'],
        #                      'ItemQuality': quality})
        #                 del data.lootList[index]
        #             elif self._autoFightInfo['notJob'] == 1 and itemTempletInfo['professionRequire'] != 0 and \
        #                     itemTempletInfo['professionRequire'] != self._owner.profession.getProfession():  # 非本职业
        #                 sellCoin += itemTempletInfo['buyingRateCoin']
        #                 data.addSellItem(
        #                     {'itemId': item['itemId'], 'itemNum': 1, 'Coin': 1 * itemTempletInfo['buyingRateCoin'],
        #                      'ItemQuality': quality})
        #                 del data.lootList[index]
        #             else:
        #                 _, itemselllist = self._owner.pack.putNewItemsInPackage(item['itemId'], 1, quality,
        #                                                                         dbItems.GET_TYPE_TEAMFIGHT)
        #                 if itemselllist:
        #                     for sellItem in itemselllist:
        #                         sellCoin += sellItem.baseInfo.getItemPrice()
        #                         data.addSellItem({'itemId': item['itemId'], 'itemNum': 1,
        #                                           'Coin': 1 * sellItem.baseInfo.getItemPrice(), 'ItemQuality': quality})
        #                         del data.lootList[index]
        #                 else:
        #                     data.addGetItem({'itemId': item['itemId'], 'itemNum': 1, 'Coin': 0, 'ItemQuality': quality})
        #     else:  # 物品
        #         _, itemselllist = self._owner.pack.putNewItemsInPackage(item['itemId'], item['itemNum'],
        #                                                                 itemTempletInfo['baseQuality'],
        #                                                                 dbItems.GET_TYPE_TEAMFIGHT)
        #         if itemselllist:
        #             for sellItem in itemselllist:
        #                 count = sellItem.pack.getStack()
        #                 sellCoin += sellItem.baseInfo.getItemPrice()
        #                 data.addSellItem({'itemId': item['itemId'], 'itemNum': count,
        #                                   'Coin': count * sellItem.baseInfo.getItemPrice(),
        #                                   'ItemQuality': itemTempletInfo['baseQuality']})
        #                 del data.lootList[index]
        #         else:
        #             data.addGetItem({'itemId': item['itemId'], 'itemNum': item['itemNum'], 'Coin': 0,
        #                              'ItemQuality': itemTempletInfo['baseQuality']})
        #
        # result = data.formatFightData(fightType, fightBossTimes=self.getFightBossTimes())
        #
        # self._owner.finance.addCoin(sellCoin)
        # self._owner.matrix.setMatrixMember()
        # self._owner.pack.SyncPackChange()
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_TEAMFIGHT)
        # self.delTeamFightTimes()
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_TEAMFIGHT, 1, changeKey=0, isAdd=True)
        # return result
        pass

    def startFightWinThread(self, target, args1=None, args2=None, args3=None):
        """开始胜利线程"""
        # winThread = Thread(target=target, args=(args1, args2, args3))
        # winThread.start()
        pass

    def doZhanJieFightWin(self, fightType, nextGuanQia, fightdata):
        """章节战斗胜利"""
        self.addExp(fightdata.partyExp)
        # self.addCoin(fightdata.partyMoney)
        # self.updatePetSoul(fightdata.partySkillPoints)  # 增加魂玉
        # if fightType == 2:
        #     if nextGuanQia:
        #         nextguankaInfo = dbZhanyi.ALL_ZHANYI_INFO.get(nextGuanQia, None)
        #         if nextguankaInfo:
        #             self._owner.task.acceptAllTask()
        #             self.setTown(nextguankaInfo['chapterId'])
        #     self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_GUANQIABOSSID, 1,
        #                                               changeKey=self._maxGuanQia, isAdd=True)

    def doZhangJie(self, fightType, bossGuanQia):
        """关卡战斗
        """
        partyid = 0
        if fightType == 1:
            guankaInfo = self._getZhanYiInfo()
            if not guankaInfo:
                ERROR_MSG("err guanqia data")
                # return self.formatErrorFightData(u'关卡错误')
                return

            partys = [guankaInfo['monsterParty1'], guankaInfo['monsterParty2'], guankaInfo['monsterParty3'],
                      guankaInfo['monsterParty4']]
            partysProbs = [guankaInfo['monsterParty1Prob'], guankaInfo['monsterParty2Prob'],
                           guankaInfo['monsterParty3Prob'], guankaInfo['monsterParty4Prob']]
            partyid = randomObject.random_pick(partys, partysProbs)
        elif fightType == 2:
            bossGuanQiaInfo = self.fillZhanYiInfoById(bossGuanQia)
            if not bossGuanQiaInfo:
                # return self.formatErrorFightData(u'BOSS关卡错误')
                return
            if bossGuanQiaInfo['needLevel'] > self.getLevel():
                # return self.formatErrorFightData(u'等级不足')
                return
            if bossGuanQia != self._maxGuanQia:
                return
                # return self.formatErrorFightData(u'不允许挑战')
            # if bossGuanQia - self._maxGuanQia > 1:
            #     return self.formatErrorFightData(u'异常挑战')
            # self._owner.guild.updateGuildTask(dbTask.TASK_CONDITION_GUANQIABOSSTIMES, 1, changeKey=0, isAdd=True)
            # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_GUANQIABOSSTIMES, 1, changeKey=0,
            #                                           isAdd=True)
            # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_FIGHTBOSS)
            partyid = bossGuanQiaInfo['monsterBossPaety']

        defHordeGroup = []  # 防守方对象
        monsterGroup = self.monsterTempletFactory(partyid)
        if not monsterGroup:
            # return self.formatErrorFightData(u'怪物组错误')
            ERROR_MSG('怪物组错误')
            return
        monsterid = ConstantDefine.MONSTER_DYNAMIC_START

        for monsterF in monsterGroup:
            monsterTempletId = monsterF['monsterTId']
            if monsterTempletId not in s_monster.datas.keys():
                ERROR_MSG('怪物模板错误')
                # return self.formatErrorFightData(u'怪物模板错误')
                return
            monster = Monster(id=monsterid, templateId=monsterTempletId, matrixId=monsterF['monsterPosition'])
            defHordeGroup.append(monster)
            monsterid += 1

        if not defHordeGroup:
            ERROR_MSG('没有怪物')
            return
        attackBattleSide = BattleSide([self])  # 进攻方阵
        attackBattleSide.setMatrixMember(2, self) # 临时加的,没有完成布阵模块之前使用
        defBattleSide = BattleSide(defHordeGroup, 2, 1)  # 防守方阵

        data = Fight(attackBattleSide, defBattleSide, partyid, self._guanqia)
        data.DoFight()

        if data.battleResult == 1:
            data.DoRewordLoot()
            # data.partyExp, data.partyMoney = self._owner.events.calculateEarningsBuff(data.partyExp, data.partyMoney)
            self.setFightWinCounts(self.getFightWinCounts() + 1)  # 胜利次数+1
            self.setFightWinOdds(self.getFightWinOdds() + 3)
            nextGuanQia = 0
            # if fightType == 2:
            #     if self._maxGuanQia == bossGuanQia:
            #         nextGuanQia = self._maxGuanQia + 1
            #         if dbZhanyi.ALL_ZHANYI_INFO.has_key(nextGuanQia):
            #             self.setMaxGuanQia(nextGuanQia, True)
            #             self.setGuanQia(nextGuanQia, clearFightInfo=True)
            # reactor.callLater(0, self.doZhanJieFightWin, fightType, nextGuanQia, data)
        else:
            if fightType == 1:
                self.setFightWinOdds(self.getFightWinOdds() - 2)

        sellCoin = 0
        # for index, item in enumerate(data.lootList):
        #     itemTempletInfo = dbItems.all_ItemTemplate.get(item['itemId'], None)
        #     if not itemTempletInfo:
        #         continue
        #     if itemTempletInfo['itemPage'] == 1:  # 装备
        #         for _ in range(item['itemNum']):
        #             if itemTempletInfo['qualityId'] != 0 and itemTempletInfo['attributeGroupId'] != 0:
        #                 quality = ItemAttributeComponent.createItemQuality(itemTempletInfo['qualityId'])
        #             else:
        #                 quality = itemTempletInfo['baseQuality']
        #
        #             # 检测挂机设置自动售卖机制
        #             if self._autoFightInfo[quality] == 1:  # 品质
        #                 sellCoin += itemTempletInfo['buyingRateCoin']
        #                 data.addSellItem(
        #                     {'itemId': item['itemId'], 'itemNum': 1, 'Coin': 1 * itemTempletInfo['buyingRateCoin'],
        #                      'ItemQuality': quality})
        #                 del data.lootList[index]
        #             elif self._autoFightInfo['notJob'] == 1 and itemTempletInfo['professionRequire'] != 0 and \
        #                     itemTempletInfo['professionRequire'] != self._owner.profession.getProfession():  # 非本职业
        #                 sellCoin += itemTempletInfo['buyingRateCoin']
        #                 data.addSellItem(
        #                     {'itemId': item['itemId'], 'itemNum': 1, 'Coin': 1 * itemTempletInfo['buyingRateCoin'],
        #                      'ItemQuality': quality})
        #                 del data.lootList[index]
        #             else:
        #                 _, itemselllist = self._owner.pack.putNewItemsInPackage(item['itemId'], 1, quality,
        #                                                                         dbItems.GET_TYPE_NOMALFIGHT)
        #                 if itemselllist:
        #                     for sellItem in itemselllist:
        #                         sellCoin += sellItem.baseInfo.getItemPrice()
        #                         data.addSellItem({'itemId': item['itemId'], 'itemNum': 1,
        #                                           'Coin': 1 * sellItem.baseInfo.getItemPrice(), 'ItemQuality': quality})
        #                         del data.lootList[index]
        #                 else:
        #                     data.addGetItem({'itemId': item['itemId'], 'itemNum': 1, 'Coin': 0, 'ItemQuality': quality})
        # else:  # 物品
        #     _, itemselllist = self._owner.pack.putNewItemsInPackage(item['itemId'], item['itemNum'],
        #                                                             itemTempletInfo['baseQuality'],
        #                                                             dbItems.GET_TYPE_NOMALFIGHT)
        # if itemselllist:
        #     for sellItem in itemselllist:
        #         count = sellItem.pack.getStack()
        #         sellCoin += sellItem.baseInfo.getItemPrice()
        #         data.addSellItem({'itemId': item['itemId'], 'itemNum': count,
        #                           'Coin': count * sellItem.baseInfo.getItemPrice(),
        #                           'ItemQuality': itemTempletInfo['baseQuality']})
        #         del data.lootList[index]
        # else:
        #     data.addGetItem({'itemId': item['itemId'], 'itemNum': item['itemNum'], 'Coin': 0,
        #                      'ItemQuality': itemTempletInfo['baseQuality']})

        result = data.formatFightData(fightType, fightBossTimes=self.getFightBossTimes())

        # self._owner.finance.addCoin(sellCoin)
        # 记录本次战斗时间信息
        nowTime = time.time()  # 获取系统当前时间(秒)

        if fightType == 1:
            if self._fightTime == 0:
                self.setFightTime(guankaInfo['fightTime'])  # 设置每局战斗时间
                # self._totlaFightTime = guankaInfo['fightTime']
            if self._totlaFightCounts != 0:  # 如果不是第一次请求
                timeDifference = nowTime - self.getFightReTime()  # 计算两次请求的间隔时间，计入战斗总时间
                # print u'本次请求间隔:%d'%timeDifference
                if guankaInfo['fightTime'] > 5:
                    if timeDifference < guankaInfo['fightTime'] - 5:
                        timeDifference = guankaInfo['fightTime'] - 5
                    if timeDifference > guankaInfo['fightTime'] + 5:
                        timeDifference = guankaInfo['fightTime'] + 5
                self._totlaFightTime += timeDifference
            else:
                self._totlaFightTime = self._fightTime

            self.setFightReTime(nowTime)  # 记录本次请求的系统时间
            self._totlaFightCounts += 1  # 战斗次数+1
            if self._totlaFightCounts > 0:  # 设置平均战斗时间
                self.setFightTime(int(self._totlaFightTime / self._totlaFightCounts), True)

        # print u'平均战斗时长:%d'%self._fightTime
        # self._owner.pack.SyncPackChange()
        return result

    def updateTask(self):
        """更新任务状态"""
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_GUANQIABOSSID, 1, changeKey=self._maxGuanQia,
        #                                           isAdd=True)
        pass

    def checkClean(self, zhangjieid):
        """检测章节是否通关
        """
        if self.currentZJ > zhangjieid:
            return True
        return False

    def fightResultFactory(self, fighttime):
        """产生快速战斗和离线战斗数据"""
        fightData = {}
        guankaInfo = self._getZhanYiInfo()
        if not guankaInfo:
            #             print 'no guanka info !!!!!!'
            return fightData
        partys = [guankaInfo['monsterParty1'], guankaInfo['monsterParty2'], guankaInfo['monsterParty3'],
                  guankaInfo['monsterParty4']]
        partysProbs = [guankaInfo['monsterParty1Prob'], guankaInfo['monsterParty2Prob'],
                       guankaInfo['monsterParty3Prob'], guankaInfo['monsterParty4Prob']]

        if self._fightTime < 20:
            fightTime = 20
        else:
            fightTime = self._fightTime

        #         print u'战斗时间%d'%self._fightTime
        fightData['FightCount'] = int(fighttime / float(fightTime))  # 战斗次数

        fightData['FightWinCount'] = int(fightData['FightCount'] * self._fightWinOdds * 0.01)  # 胜利次数
        fightData['FightStartLevel'] = self._owner.level.getLevel()  # 开始等级
        fightData['FightExp'] = 0  # 获取经验
        # fightData['FightMoney'] = 0  # 获取金钱
        # fightData['FightSkillPoints'] = 0  # 获取技能点
        # fightData['SkillProficiency'] = []
        # fightData['BigDropCount'] = 0  # 大爆次数
        # fightData['GetEquipInfo'] = {}  # 掉落装备信息
        # oddsTotla = 0
        # for odds in partysProbs:
        #     oddsTotla += odds
        #
        # #         print u'战斗时间2%d'%self._fightTime
        # rewardCounts = fightData['FightWinCount']
        # for index, partyId in enumerate(partys):
        #     partyInfo = dbMonster.ALL_MONSTER_PARTY_INFO.get(partyId)
        #     if not partyInfo:
        #         continue
        #     if index + 1 == len(partys):
        #         fightPartyCounts = rewardCounts
        #     else:
        #         fightPartyCounts = int(round(fightData['FightWinCount'] * (partysProbs[index] / float(oddsTotla))))
        #     if fightPartyCounts < 1:
        #         fightPartyCounts = 1
        #     if fightPartyCounts > rewardCounts:
        #         fightPartyCounts = rewardCounts
        #
        #     fightData['FightExp'] += fightPartyCounts * partyInfo['exp']  # 获取经验
        #     fightData['FightMoney'] += fightPartyCounts * partyInfo['money']  # 获取金钱
        #     fightData['FightSkillPoints'] += fightPartyCounts * partyInfo['skillPoints']  # 获取技能点
        #     rewardCounts -= fightPartyCounts
        #     if rewardCounts <= 0:
        #         break
        #
        # #         print u'战斗时间3%d'%self._fightTime
        #
        # guankaInfo = self._getZhanYiInfo()
        #
        # dropCount = int(fightData['FightWinCount'] * guankaInfo.get('dropOdds', 0) * 0.0001)  # 掉落次数
        # dropItemList = self.rewordLootFactory(dropCount)  # 产生掉落
        # if dropItemList:
        #     for itemlootInfo in dropItemList:
        #         itemTempletInfo = dbItems.all_ItemTemplate.get(itemlootInfo.get('itemId', 0), {})
        #         if not itemTempletInfo:
        #             continue
        #         if itemTempletInfo['qualityId'] != 0 and itemTempletInfo['attributeGroupId'] != 0:
        #             quality = ItemAttributeComponent.createItemQuality(itemTempletInfo['qualityId'])
        #         else:
        #             quality = itemTempletInfo['baseQuality']
        #         if quality == 0:
        #             quality = itemTempletInfo['baseQuality']
        #
        #         if not fightData['GetEquipInfo'].has_key(quality):
        #             fightData['GetEquipInfo'][quality] = {'Count': 0, 'Money': 0, 'SellCount': 0}
        #         fightData['GetEquipInfo'][quality]['Count'] += itemlootInfo['itemNum']
        #         # 检测挂机设置自动售卖机制
        #         if self._autoFightInfo[quality] == 1 and itemTempletInfo['itemPage'] == 1:  # 品质
        #             count = itemlootInfo['itemNum']
        #             sellCoin = itemTempletInfo['buyingRateCoin']
        #             fightData['GetEquipInfo'][quality]['Money'] += count * sellCoin
        #             fightData['GetEquipInfo'][quality]['SellCount'] += count
        #         elif self._autoFightInfo['notJob'] == 1 and itemTempletInfo['professionRequire'] != 0 and \
        #                 itemTempletInfo['professionRequire'] != self._owner.profession.getProfession() and \
        #                 itemTempletInfo['itemPage'] == 1:  # 非本职业
        #             count = itemlootInfo['itemNum']
        #             sellCoin = itemTempletInfo['buyingRateCoin']
        #             fightData['GetEquipInfo'][quality]['Money'] += count * sellCoin
        #             fightData['GetEquipInfo'][quality]['SellCount'] += count
        #         else:
        #             package = self._owner.pack
        #             _, itemselllist = package.putNewItemsInPackage(itemlootInfo['itemId'], itemlootInfo['itemNum'],
        #                                                            quality, dbItems.GET_TYPE_FASTFIGHT)
        #             for sellItem in itemselllist:
        #                 count = sellItem.pack.getStack()
        #                 sellCoin = sellItem.baseInfo.getItemPrice()
        #                 fightData['GetEquipInfo'][quality]['Money'] += count * sellCoin
        #                 fightData['GetEquipInfo'][quality]['SellCount'] += count
        #
        # #         print u'战斗时间4%d'%self._fightTime
        # # 服务器结算快速或离线战斗
        # # 结算经验
        # self._owner.level.addExp(fightData['FightExp'])
        # fightData['FightEndLevel'] = self._owner.level.getLevel()  # 结束等级
        # # 结算金币
        # addCoin = fightData['FightMoney']
        # for EquipInfo in fightData['GetEquipInfo'].values():
        #     addCoin += EquipInfo['Money']
        #
        # self._owner.finance.addCoin(addCoin)
        #
        # # self._owner.skillsAdorn.addSkillPoints(fightData['FightSkillPoints'])
        #
        # #         if fightData['FightCount'] > 0:
        # #             fightData['SkillProficiency'].extend(self._owner.skillsAdorn.updateSkillProficiency(fightData['FightCount']+fightData['FightWinCount'] * 2))#增加技能熟练度
        #
        # #         print u'战斗时间5%d'%self._fightTime
        # #         print  fightData
        # return fightData
        pass

    def rewordLootFactory(self, count):
        """产生掉落"""
        # lootList = []
        # guankaInfo = self._getZhanYiInfo()
        # if not guankaInfo:
        #     #             print 'no guanka info !!!!!!'
        #     return lootList
        # partys = [guankaInfo['monsterParty1'], guankaInfo['monsterParty2'], guankaInfo['monsterParty3'],
        #           guankaInfo['monsterParty4']]
        # partysProbs = [guankaInfo['monsterParty1Prob'], guankaInfo['monsterParty2Prob'],
        #                guankaInfo['monsterParty3Prob'], guankaInfo['monsterParty4Prob']]
        # oddsTotla = 0
        # for odds in partysProbs:
        #     oddsTotla += odds
        #
        # for _ in range(count):
        #     odds = random.randint(0, oddsTotla)  # 随机值
        #     cumulative_probability = 0
        #     for index, partyId in enumerate(partys):
        #         cumulative_probability += partysProbs[index]
        #         if odds <= cumulative_probability:
        #             partyInfo = dbMonster.ALL_MONSTER_PARTY_INFO.get(partyId)
        #             if not partyInfo:
        #                 #                         print u'partyInfo:%d'%partyId
        #                 continue
        #             lootList.extend(WorldManager().dropItem(partyInfo['lootGroupId']))
        #             break
        #
        # return lootList
        pass

    def calculateFightResult(self, fastType, fastTime):
        """
        计算和结算快速战斗和离线战斗收益
        @type 类型 ：1 快速战斗 2：离线战斗
        @fastTime 时间：单位(秒)
        """
        # FightResult = guaji_pb2.MsgFastFightResult()
        #
        # if fastType == 1:
        #     if not self._owner.checkSystemTimes(dbGameConfig.FAST_FIGHT):
        #         FightResult.Result = 'FALSE'
        #         FightResult.ResultInfo = u'今日次数已经用光!'
        #         return FightResult
        #     if not self._owner.checkSystemExpend(dbGameConfig.FAST_FIGHT, dbGameLog.SYSTEM_ID_FASTFIGHT):
        #         FightResult.Result = 'FALSE'
        #         FightResult.ResultInfo = u'缺少所需消耗!'
        #         return FightResult
        #     self.delFastFightTimes()
        #
        # FightResult.Result = 'TRUE'
        # FightResult.Type = fastType
        # FightResult.Time = fastTime
        # FightResult.FastFightTimes = self.getFastFightTimes()
        # fastFightData = self.fightResultFactory(fastTime)
        # FightResult.FightCount = fastFightData.get('FightCount', 0)
        # FightResult.FightWinCount = fastFightData.get('FightWinCount', 0)
        # FightResult.FightStartLevel = fastFightData.get('FightStartLevel', 0)
        # FightResult.FightEndLevel = fastFightData.get('FightEndLevel', 0)
        # FightResult.FightExp = fastFightData.get('FightExp', 0)
        # FightResult.FightMoney = fastFightData.get('FightMoney', 0)
        # FightResult.BigDropCount = fastFightData.get('BigDropCount', 0)
        # FightResult.SkillPoints = fastFightData.get('FightSkillPoints', 0)
        # for quality, equipInfo in fastFightData['GetEquipInfo'].items():
        #     addEquipInfo = FightResult.GetEquipInfo.add()
        #     addEquipInfo.Quality = quality
        #     addEquipInfo.Money = equipInfo['Money']
        #     addEquipInfo.Count = equipInfo['Count']
        #     addEquipInfo.SellCount = equipInfo['SellCount']
        #
        # for skillAddProficiency in fastFightData['SkillProficiency']:
        #     proficiencyInfo = FightResult.SkillProficiency.add()
        #     proficiencyInfo.SkillId = skillAddProficiency['skillId']
        #     proficiencyInfo.AddProficiency = skillAddProficiency['AddProficiency']
        #     proficiencyInfo.OldLevel = skillAddProficiency['oldLevel']
        #     proficiencyInfo.NewLevel = skillAddProficiency['newLevel']

        #         print u'离线数据: %s'%FightResult

        # return FightResult
        pass

    def calculateOffLineFightResult(self):
        """计算离线战斗结果"""
        # if self._owner.level.getExp() <= 0 and self._owner.level.getLevel() <= 1:
        #     self._FightResult = self.calculateFightResult(2, 0)
        #     return
        # if self._offLineTime > 3600 * 24:
        #     self._offLineTime = 3600 * 24
        #
        # #         if self._offLineTime > 60 * 10:
        # #             self._owner.events.updateEventValue(100) #事件值
        #
        # self._FightResult = self.calculateFightResult(2, int(self._offLineTime))
        # self._offLineTime = 0
        pass

    def getOffLineFightResult(self):
        """获取离线挂机数据"""
        # print u'发送离线数据:%s'%self._FightResult
        # return self._FightResult.SerializePartialToString()
        pass

    def getFastFightResult(self):
        """获取快速战斗结果，快速战斗固定为2小时"""
        # fastFightResult = self.calculateFightResult(1, int(7200))
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_FASTFIGHT, 1, changeKey=0, isAdd=True)
        # self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_FASTFIGHT)
        # return fastFightResult.SerializePartialToString()
        pass

    def refreshTeamFightMember(self):
        """刷新组队战队员"""
        # del self._teamFightMember[:]
        # intervallevel = 0
        # while len(self._teamFightMember) < 6 and intervallevel <= 115:
        #     intervallevel += 5
        #     queryTeamMember = dbuser.findUserBuyLevelRandom(self._owner.level.getLevel(), intervallevel,
        #                                                     self._owner.getBaseID(), 6)
        #     for teamMember in queryTeamMember:
        #         if len(self._teamFightMember) < 6 and teamMember['id'] not in self._teamFightMember:
        #             self._teamFightMember.append(teamMember['id'])
        # rivalList = []
        # for teamMemberId in self._teamFightMember:
        #     rivalList.append(tb_character_admin.getObjData(teamMemberId))
        # return rivalList
        pass

    def resetTeamFightTimes(self):
        """重置组队战次数"""
        # if not self._owner.checkSystemTimes(dbGameConfig.TEAM_RESET):
        #     return False, u'次数已经用完'

        # if self.getTeamResetFreeTimes() <= 0:
        #     if not self._owner.checkSystemExpend(dbGameConfig.TEAM_RESET,dbGameLog.SYSTEM_ID_TEAMTIMES):
        #         return False, u'货币不足'
        # else:
        #     self.delResetTeamFightFreeTimes()
        #
        # # self.delResetTeamFightTimes()
        if not self._owner.checkSystemExpend(dbGameConfig.TEAM_RESET, dbGameLog.SYSTEM_ID_TEAMTIMES):
            return False, u'货币不足'
        # self.setTeamFightTimes(self._owner.getSystemTotalTimes(dbGameConfig.TEAM_FIGHT))
        self.addTeamFightTimes()
        self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_RESETTEAMFIGHT, 1, changeKey=0, isAdd=True)
        self._owner.addSystemUseRecord(dbGameLog.SYSTEM_ID_TEAMTIMES)
        return True, u''

    def fastFightBoss(self, bossGuanQia):
        """扫荡BOSS"""
        # if self.getFightBossTimes() <= 0:
        #     return False,u'次数不足'
        # if self._owner.pack.countItemTemplateId(dbItems.FIGHTBOSS_POINT) > 0:
        #     self._owner.pack.delItemByTemplateId(dbItems.FIGHTBOSS_POINT, 1, u'BOSS扫荡')
        # else:
        #     return False, u'缺少道具'
        # if self._maxGuanQia <= bossGuanQia:
        #     return False, u'未通关'
        # bossGuanQiaInfo = self.fillZhanYiInfoById(bossGuanQia)
        # if not bossGuanQiaInfo:
        #     return False, u'关卡错误'
        # partyInfo = dbMonster.ALL_MONSTER_PARTY_INFO.get(bossGuanQiaInfo['monsterBossPaety'])
        # dropList = WorldManager().dropItem(partyInfo['lootGroupId'], partyInfo['lootNumber'])
        # self._owner.level.addExp(partyInfo['exp'])
        # self._owner.finance.addCoin(partyInfo['money'])
        # self._owner.pet.updatePetSoul(partyInfo['skillPoints'])  # 增加魂玉
        # self._owner.pack.putNewItemListInPack(dropList, u'扫荡BOSS')
        # # self.delFightBossTimes()
        # self._owner.guild.updateGuildTask(dbTask.TASK_CONDITION_GUANQIABOSSTIMES, 1, changeKey=0, isAdd=True)
        # self._owner.task.updateTaskConditionValue(dbTask.TASK_CONDITION_GUANQIABOSSTIMES, 1, changeKey=0, isAdd=True)
        # return True, {'exp': partyInfo['exp'], 'Money': partyInfo['money'], 'soulPoint': partyInfo['skillPoints'],
        #               'dropList': dropList}
        pass
